﻿/**********************************************************************
/// <summary>
// Name of File     : LoggingManager.cs
// Author           : Parminder Singh
// Create date      : 17th Sep 2011
/// </summary>
************************************************************************/
using System;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace Crystal.CLL
{
   public class LoggingManager
   {
       #region Methods
       private static string PrepareMessage(string UserName, string ErrorMessage, string Summary)
       {
           StringBuilder LogMessage = null;
           LogMessage = new StringBuilder();
           LogMessage.Append("User Name - ");
           LogMessage.Append(UserName);
           LogMessage.Append(Environment.NewLine);
           LogMessage.Append(Summary);
           LogMessage.Append(Environment.NewLine);
           LogMessage.Append("Error Message - ");
           LogMessage.Append(ErrorMessage);
           return LogMessage.ToString();
       }
       public static bool WriteLog(string UserName, string ErrorMessage, string Summary)
       {
           try
           {
               LogEntry _Log = new LogEntry();
               _Log.Message = PrepareMessage(UserName, ErrorMessage, Summary);
               _Log.TimeStamp = DateTime.Now;
               Logger.Write(_Log);
               return true;
           }
           catch
           {
               return false;
           }
       }
       #endregion
    }
}
